<!--
@since 2018/05/27
@modified 2021/05/16 23:44:33
-->

{% init key = "" %}
{% init parent_note = None %}

{% if key != None and key != "" %}
    <div class="card">
        <div class="search-tab">
            <a class="link" href="/search?key={{?key}}&category=default" 
                data-option="default" data-value="{{?category}}">默认</a>
            
            <a class="link" href="/search?key={{?key}}&search_type=note" 
                data-option="note" data-value="{{?category}}">笔记</a>

            <a class="link" href="/search?key={{?key}}&category=content" 
                data-option="content" data-value="{{?category}}">内容</a>

            <a class="link" href="/search?key={{?key}}&search_type=dict" 
                data-option="dict" data-value="{{?category}}">词典</a>
            
            <a class="link" href="/search?key={{?key}}&search_type=task"
                data-option="task" data-value="{{?category}}">待办</a>

            <a class="link" href="/message?tag=search&key={{?key}}&p=log&from=note" 
                data-option="message" data-value="{{?category}}">记事</a>
        </div>
    </div>
{% end %}

{% if parent_note != None %}
    <div class="card btn-line-height">
        <span>搜索目录:</span>
        <a href="{{parent_note.url}}">{{parent_note.name}}</a>
        <div class="float-right">
            <a class="btn btn-default" href="/search?key={{key}}&search_type=note">搜索全站</a>
        </div>
    </div>
{% end %}

<script type="text/javascript">
$(function () {
    var searchType = getUrlParam("search_type");
    var category   = getUrlParam("category");

    function isEmpty(value) {
        return value === "" || value === undefined || value === null
    }

    if (!isEmpty(searchType)) {
        $("[data-option=" + searchType + "]").addClass("selected-link");
    } else if (!isEmpty(category)) {
        $("[data-option=" + category + "]").addClass("selected-link");
    } else {
        $("[data-option=default]").addClass("selected-link");
    }
})
</script>